#include "ObjectRecognition.h"
#include <iostream>

ObjectRecognition::ObjectRecognition(const std::string& classifierPath)
    : classifierPath(classifierPath) {
}

ObjectRecognition::~ObjectRecognition() {}

bool ObjectRecognition::initialize() {
    if (!classifier.load(classifierPath)) {
        std::cerr << "Error loading classifier from: " << classifierPath << std::endl;
        return false;
    }
    return true;
}

std::vector<cv::Rect> ObjectRecognition::recognize(const cv::Mat& inputImage) {
    std::vector<cv::Rect> objects;
    if (classifier.empty()) {
        std::cerr << "Classifier is not initialized." << std::endl;
        return objects;
    }

    cv::Mat grayImage;
    cv::cvtColor(inputImage, grayImage, cv::COLOR_BGR2GRAY);
    cv::equalizeHist(grayImage, grayImage);

    classifier.detectMultiScale(grayImage, objects, 1.1, 3, 0, cv::Size(30, 30));
    return objects;
}